package net.googlecode.demenkov.task4.utils;

import net.googlecode.demenkov.task4.source.StringUtil;

import java.util.StringTokenizer;

/**
 * Makes first letters in every word in uppercase.
 *
 * @author Yura Demenkov
 * @since 04.04.11
 */
public class UpperFirst extends StringUtil {

    /**
     * Constructor that create StringUtil and assosiate it with inputstring.
     *
     * @param inputstring
     */
    public UpperFirst(String inputstring) {
        super(inputstring);
    }

    /**
     * Makes first letters in every word in uppercase and log this action.
     *
     * @Corrected string.
     */
    public String MakeFirstUpper() {
        String outputString = new String();
        StringTokenizer st = new java.util.StringTokenizer(inputString, " ", true);
        StringBuilder sb = new StringBuilder();
        while (st.hasMoreTokens()) {
            String token = st.nextToken();
            sb.append(Character.toUpperCase(token.charAt(0)));
            sb.append(token.substring(1));
        }
        outputString = sb.toString();
        this.LogMessage(outputString, "Makes first letter in every word in uppercase.");
        return outputString;
    }
}
